package keeto.com.vn.bms.ui.adapter;

import hirondelle.date4j.DateTime;

import java.util.ArrayList;

import keeto.com.vn.bms.ui.activity.R;

import android.R.anim;
import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class CalWeekendAdapter  extends BaseAdapter{
	private Context context;
	private ArrayList<DateTime> arrWeek;
	private LayoutInflater inflater;
	private int index = -1;


	public CalWeekendAdapter(Context context, ArrayList<DateTime> arrWeek, int index) {
		super();
		this.context = context;
		this.arrWeek = arrWeek;
		this.index = index;
		this.inflater = LayoutInflater.from(context);
	}



	public int getIndex() {
		return index;
	}



	public void setIndex(int index) {
		this.index = index;
	}



	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return arrWeek.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return arrWeek.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		TextView tvDate;
		convertView = inflater.inflate(R.layout.item_calendar, null);
		tvDate = (TextView)convertView.findViewById(R.id.tv_date_cal);
		DateTime dateTime = arrWeek.get(position);
		if (dateTime != null){
			if(dateTime.getWeekDay() == 7 || dateTime.getWeekDay() == 1){
				tvDate.setTextColor(context.getResources().getColor(R.color.tv_color));
			}else{
				tvDate.setTextColor(context.getResources().getColor(R.color.black_white_selector));
			}
			tvDate.setText(dateTime.getDay() + "");

		}else{
			tvDate.setText("");
		}
		if (index != -1)
			changeStatus(index, tvDate);

		return convertView;
	}
	@SuppressLint("ResourceAsColor") public void changeStatus(int select, TextView textView){
		for (int i=0; i<arrWeek.size(); i++){
			if (textView.getText().toString().equals(arrWeek.get(index).getDay() +"")){
				textView.setSelected(true);
			}else{
				textView.setSelected(false);

			}
		}


	}
}
